package com.bifrost.repository;

import com.bifrost.entity.Product;
import com.bifrost.entity.ProductOption;
import com.bifrost.entity.ProductOptionValue;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author rangf
 * @date 2018/3/5
 */
public interface ProductOptionValueRepository extends JpaRepository<ProductOptionValue, Long> {

    /**
     * 获取商品属性值
     *
     * @param productId productId
     * @param optionId optionId
     * @return
     */
    @Query(value = "SELECT * FROM `PRODUCT_OPTION_VALUE` P WHERE P.PRODUCT_ID=?1 AND P.PRODUCT_OPTION_ID=?2", nativeQuery = true)
    List<ProductOptionValue> getProductOptionValues(Long productId, Long optionId);

    List<ProductOptionValue> getAllByProduct(Product product);

    void deleteByProductOptionAndAttributeValue(ProductOption finalPersistenceOption, String optionName);

    ProductOptionValue findFirstByAttributeValueAndProductOption(String attributeValue, ProductOption option);
}
